package com.zsy.petshop_01.service.impl;

import com.zsy.petshop_01.common.result.ResponseResult;
import com.zsy.petshop_01.model.entity.VIPMessage;
import com.zsy.petshop_01.manager.VIPManager;
import com.zsy.petshop_01.model.entity.VIPVideo;
import com.zsy.petshop_01.model.vo.vip.PublishVideoVo;
import com.zsy.petshop_01.model.vo.vip.UpdateVideoVo;
import com.zsy.petshop_01.service.VIPService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

@Service
public class VIPServiceImpl implements VIPService {
    @Autowired
    VIPManager vipManager;

    @Override
    public ResponseResult<?> selectAll() {
        List<VIPMessage> vipMessages = vipManager.selectAll();
        return ResponseResult.success("OK",vipMessages);
    }

    @Override
    public ResponseResult<?> selectByUserName(String userName) {
        List<VIPMessage> vipMessages = new ArrayList<>();
        if(userName!=null) {
            vipMessages = vipManager.selectByUserName(userName);
        }else{
            vipMessages = vipManager.selectAll();
        }
        return ResponseResult.success("OK",vipMessages);
    }

    @Override
    public ResponseResult<?> publish(String message, HttpServletRequest request)  {
        String userId = request.getHeader("user_id");
        vipManager.publish(message,Integer.parseInt(userId));
        return ResponseResult.success("OK");
    }

    @Override
    public ResponseResult<?> delete(Integer id) {
        vipManager.delete(id);
        return ResponseResult.success("OK");
    }

    @Override
    public ResponseResult<?> watchMonitoring() {
        return ResponseResult.success("OK");
    }

    @Override
    public ResponseResult<?> publishVideo(PublishVideoVo publishVideoVo) {
        vipManager.publishVideo(publishVideoVo);
        return ResponseResult.success("OK");
    }

    @Override
    public ResponseResult<?> updateVideo(UpdateVideoVo updateVideoVo) {
        vipManager.updateVideo(updateVideoVo);
        return ResponseResult.success("OK");
    }

    @Override
    public ResponseResult<?> deleteVideo(Integer id) {
        vipManager.deleteVideo(id);
        return ResponseResult.success("OK");
    }

    @Override
    public ResponseResult<?> selectAllVideo() {
        List<VIPVideo> vipVideos = vipManager.selectAllVideo();
        return ResponseResult.success(vipVideos);
    }
}
